/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Administrator
 */
import java.util.*;

 public class AppCalendar{static int[] day={31,28,31,30,31,30,31,31,30,31,30,31};
 static String[] weeks={"星期天","星期一","星期二","星期三","星期四","星期五","星期六"};
 public static void main(String[] args){
     try{
         Scanner input=new Scanner(System.in);
         System.out.println("请入一个年份和一个月份（以回车分段）:");
         int year=input.nextInt();
         int month=input.nextInt();
         monthCalendar(year,month-1);
         System.out.println("请输入一个年份，一个月份，一个日（以回车分段）：");
         year=input.nextInt();
         month=input.nextInt();
         int d=input.nextInt();
         Calendar c1=GregorianCalendar.getInstance();
         c1.set(Calendar.YEAR, year);
         c1.set(Calendar.MONTH, month-1);
         c1.set(Calendar.DATE,d);
         System.out.println("你输入的日期是"+getWeekName(c1));
        System.out.println("请再输入一个年份，一个月份，一个日：");
        year=input.nextInt();
        month=input.nextInt();
         d=input.nextInt();
         Calendar c2=GregorianCalendar.getInstance();
         c2.set(Calendar.YEAR, year);
         c2.set(Calendar.MONTH, month-1);
         c2.set(Calendar.DATE,d);
         System.out.println("你输入的日期是"+getWeekName(c2));
         getDays(c1,c2);
     }catch(Exception e){ e.printStackTrace();}
 }


 public static void monthCalendar(int year,int month){
     Calendar c=GregorianCalendar.getInstance();
     System.out.println("------------"+year+"年"+(month+1)+"月------------");
     System.out.println("SUN MON TUE WED THU FRI SAT");
     c.set(Calendar.YEAR, year);
     c.set(Calendar.MONTH, month);
     c.set(Calendar.DATE,1);
     int first=c.get(Calendar.DAY_OF_WEEK);
     int i;
     for(i=1;i<first;i++)
         System.out.print("    ");
 //System.out.print(" ");
     for(i=1;i <=day[month-1];i++)
     {
         if(i <10) System.out.print(" ");
         System.out.print(" "+i);
         System.out.print(" ");
         if(first++%7==0)
             System.out.println();
     }
     System.out.println("");
 }
 public static String getWeekName(Calendar c){
     return weeks[c.get(Calendar.DAY_OF_WEEK)-1] ;
 }
 public static long getDays(Calendar c1,Calendar c2){
     Date d1=c1.getTime();
     Date d2=c2.getTime();
     long daterange=Math.abs(d1.getTime()-d2.getTime()); //getTime()返回自 1970 年 1 月 1 日 00:00:00 GMT 以来此 Date对象表示的毫秒数。
     long time=1000*3600*24; //一天的微秒数
     System.out.println("两个日期相隔"+daterange/time+"天");
     return daterange/time;
 }
 }


